/*
 *  Copyright 2008 Mark Ashworth <javameme@gmail.com>.
 * 
 *  Licensed under the GNU General Public License v3 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 * 
 *       http://www.gnu.org/licenses/gpl-3.0.html
 * 
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  under the License.
 */

package xperiment.metaphor.service;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import xperiment.metaphor.persistence.filter.Query;
import xperiment.metaphor.persistence.filter.SearchCriteria;
import xperiment.metaphor.service.action.PersistAction;

/**
 *
 * @author Mark Ashworth <javameme@gmail.com>
 * @version 1.0.0
 */
public interface DomainService {

    /**
     * Retrieves the persistent object of type T
     * @param persistentClass The class of the object to retrieve
     * @return List
     */
    List retrieve(Class persistentClass);
    
    /**
     * Retrieves the persistent object of type T that match the query
     * @return List
     */
    List retrieve(Query query);
    
    /**
     * Retrieves the persistent object of type T that match the search criteria
     * @return List
     */
    List retrieve(SearchCriteria searchCriteria);
    
    /**
     * Retrieves the persistent object by id
     * @param persistentClass The class of the object to retrieve
     * @param id The id of the persistent object
     * @return T
     */
    Object retrieveById(Class persistentClass, Serializable id);
    
    /**
     * Adds a persist action to be called before and after the object has been
     * persisted to the persistence store. This could be used for example to 
     * encode the password just before persisted to the store.<br />
     * 
     * The order that the actions are performed are implementation specific.<br />
     * 
     * @param persistAction The persist action to be performed
     */
    void addPersistAction(PersistAction persistAction);
    
    /**
     * Removes the persist action
     * @param persistAction The persist action to remove
     */
    void removePersistAction(PersistAction persistAction);
    
    /**
     * Sets the persist actions
     * @param persistActions The new value
     */
    void setPersistActions(Collection<PersistAction> persistActions);
    
    /**
     * Returns the persist actions
     * @return Collection
     */
    Collection<PersistAction> getPersistActions();
    
    /**
     * Saves the persistent object and returns the persistent object with it's
     * new unique identifier.
     * @param object The object to save
     * @return Object
     */
    Object save(Object object);
    
    /**
	 * Deletes the object
	 * @param object The object to delete
     * @throws org.springframework.dao.DataAccessException If there was an database error
	 */
	void delete(Object object);
    
    /**
     * Deletes a list of persistent objects
     * @param objects The objects to delete
     * @throws org.springframework.dao.DataAccessException If there was an database error
     */
    void delete(List<Object> objects);
}
